package com.yotoodesign.dianba.fragment;

import java.util.ArrayList;

import android.support.v4.app.Fragment;

import com.yotoodesign.dianba.bean.BaseData;
import com.yotoodesign.dianba.ui.MainActivity;

/*
 * 
 */
public abstract class BaseFragment extends Fragment {
	/*
	 * 是否已经初始化好
	 */
	private boolean inited = false;
	/*
	 * 数据是否发生变化
	 */
	private boolean changed = false;
	/*
	 * 数据列表
	 */
	private ArrayList<BaseData> dataList;
	/*
	 * 源数据列表，搜索前保存前数据
	 */
	private ArrayList<BaseData> sourceList;
	
	/*
	 * 主活动
	 */
	private MainActivity main;
	/*
	 * 历史输入的拼音
	 */
	private String historyPinyin;
	
	/*
	 * 基本数据
	 */
	private BaseData data;
	
	
	public BaseData getData() {
		return data;
	}

	public void setData(BaseData data) {
		this.data = data;
	}

	public String getHistoryPinyin() {
		return historyPinyin;
	}

	public void setHistoryPinyin(String historyPinyin) {
		this.historyPinyin = historyPinyin;
	}

	public ArrayList<BaseData> getSourceList() {
		return sourceList;
	}

	public void setSourceList(ArrayList<BaseData> sourceList) {
		this.sourceList = sourceList;
	}

	public ArrayList<BaseData> getDataList() {
		return dataList;
	}

	public void setDataList(ArrayList<BaseData> dataList) {
		this.dataList = dataList;
		if(!changed){
			this.sourceList = new ArrayList<BaseData>();
			for(int i = 0;i<dataList.size();i++){
				sourceList.add(dataList.get(i));
			}
			changed = true;
		}
	}
	
	@Override
	public void onPause() {
		super.onPause();
		main = (MainActivity)this.getActivity();
		this.historyPinyin = main.getPinYin();
	}
	
	@Override
	public void onResume() {
		super.onResume();
		
		main = (MainActivity)this.getActivity();
		main.setCurrentFragment(this);
		main.setPinYin(historyPinyin);
	}
	
	/*更新列表*/
	abstract public void updateListView();

	public boolean isInited() {
		return inited;
	}

	public void setInited(boolean inited) {
		this.inited = inited;
	}
}
